//package com.xiguaji.tiktok.task.blogger.event;
//
//import com.google.common.eventbus.AllowConcurrentEvents;
//import com.google.common.eventbus.Subscribe;
//import com.gugee.tiktok.common.model.dal.blogger.BloggerLogRepository;
//import com.gugee.tiktok.common.model.dal.blogger.BloggerMainRepository;
//import com.gugee.tiktok.common.model.mysql.BloggerLog;
//import com.gugee.tiktok.common.model.mysql.BloggerMain;
//import com.xiguaji.boot.eventbus.Event;
//import com.xiguaji.boot.eventbus.EventBusTemplate;
//import com.xiguaji.boot.eventbus.IEventListener;
//import com.xiguaji.tiktok.task.common.config.AppConfig;
//import lombok.val;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.util.List;
//import java.util.Optional;
//
//@Component
//public class ESRefreshBloggerMainEventListener implements IEventListener<ESRefreshBloggerMainEventListener.ESRefreshBloggerMainEvent> {
//    @Autowired
//    BloggerLogRepository bloggerLogRepository;
//
//    @Autowired
//    BloggerMainRepository bloggerMainRepository;
//
//    @Autowired
//    @Lazy
//    EventBusTemplate eventBusTemplate;
//    @Autowired
//    AppConfig appConfig;
//    @Override
//    @Subscribe
//    @AllowConcurrentEvents
//    public void handle(ESRefreshBloggerMainEvent event) {
//        int bloggerLogType = BloggerLog.BloggerLogType.ES_REFRESH_BLOGGER_MAIN_LOOP.getValue();
//
//        Optional<BloggerLog> bloggerLogOptional = bloggerLogRepository.findByLogType(bloggerLogType);
//        BloggerLog bloggerLog;
//
//        long id = 0;
//        if (bloggerLogOptional.isPresent()) {
//            id = bloggerLogOptional.get().getCurrentBloggerId();
//            bloggerLog = bloggerLogOptional.get();
//        } else {
//            bloggerLog = new BloggerLog();
//            bloggerLog.setLogType(bloggerLogType);
////            bloggerLog.setExtValue("");
//            bloggerLog.setCreateBy(event.getSource());
//            bloggerLog.setUpdateBy(event.getSource());
//        }
//
//        List<BloggerMain> bloggers = bloggerMainRepository.findBloggersByIdAndCount(appConfig.getSysCollectFollowerCount(),id, 2000);
//        if (CollectionUtils.isEmpty(bloggers)) {
//            bloggerLog.setCurrentBloggerId(0);
//            bloggerLogRepository.save(bloggerLog);
//            return;
//        }
//        bloggerLog.setCurrentBloggerId(bloggers.get(bloggers.size() - 1).getId());
//        bloggerLogRepository.save(bloggerLog);
//
//        val esSaveBloggerMainEvent = new ESSaveBloggerMainEventListener.ESSaveBloggerMainEvent(event,bloggers);
//        eventBusTemplate.post(esSaveBloggerMainEvent);
//    }
//
//
//    public static class ESRefreshBloggerMainEvent extends Event {
//
//        public ESRefreshBloggerMainEvent() {
//            super( "ESRefreshBloggerMain");
//        }
//    }
//}
